<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <title>创建会员</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
     <style type="text/css">
			table td{
			text-align: center;
			}
		 	table th{
				text-align: center;
		 	}
		 	.col-sm-6 {
			    width: 500px;
			}
			.control-labels{
				margin-left:50px;
				padding-top: 7px;
				float: left;
			}
	
			.red{
				color: red;
			}
			.green{
				color: lightblue;
			}
			.pcc{
				width: 110px;
				height: 34px;
			}
		</style>
</head>

<body>
 
<div id="wrapper">
	<c:if test="${VipPower==0}"> 
	<div id="page-wrapper" style="text-align:center;font-size: 18px ;"> 
  		<span style="padding-top: 400px;position: absolute;">您没该相关权限！</span>
    </div>
   </c:if>
 <c:if test="${VipPower==1 }">
 	<div class="col-lg-10 ">
			<h1 class="page-header">新建会员</h1>
			<div class="pull-right">
				<button class="btn btn-success " onclick="query();">保存</button>
				<button class="btn btn-success " onclick="reset();">重置</button>
			</div>		
	</div>
		
	<form id="addForm" action="${BASE_PATH}/bus/user/doAdd" method="post" class="form-horizontal" >
		<div class="form-group">
		    <label class="col-sm-3 control-label">手机号：</label>
		    <div class="col-sm-6">
	        	<input type="text" name="aphone" id="aphone" class="form-control" placeholder="输入会员手机号" required autocomplete="off" onblur="upperCase()" >
	        	<span id="mess"></span>
		    </div>
		</div>
		<div class="form-group">
		    <label class="col-sm-3 control-label">姓名：</label>
		    <div class="col-sm-6">
	        	<input type="text" name="aname" value="" class="form-control" placeholder="输入会员姓名" required autocomplete="off" maxlength="20">
		    </div>
		</div>
		<div class="form-group">
		    <label class="col-sm-3 control-label">性别：</label>
		    <div class="col-sm-6">
			    <input name="radio"  type="radio" value="2" > 男 &nbsp;&nbsp;&nbsp;&nbsp;
			    <input name="radio"  type="radio" value="1" checked> 女
		    </div>
		</div>
		<div class="form-group">
		    <label class="col-sm-3 control-label">会员生日：</label>
		    <div class="col-sm-6">
	        	<input type="text" id="birthday" name="birthday" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd"  required autocomplete="off">
		    </div>
		</div>
		<div class="form-group">
		    <label class="col-sm-3 control-label">会员状态：</label>
		    <div class="col-sm-6">
	        	<select name="state" class="selectpicker" id="state" required>
					<option value="1">未登录</option>
					<option value="2">未注册</option>
					<option value="3">会员</option>
		        </select>
		    </div>
		</div>
		<div class="form-group yh">
		    <label class="col-sm-3 control-label yc">登录日期：</label>
		    <div class="yc">
	        	<input type="text" id="yuchan" name="yuchanthday" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd"  autocomplete="off">
		    </div>
		      <label class="col-sm-3 control-label bb">升级日期：</label>
		    <div class="bb">
	        	<input type="text" id="babythday" name="babythday" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd"  autocomplete="off">
		    </div>
		     <label class=" control-labels">等级：</label>
	        <div class="col-sm-6 ">
	        	<select name="taici" class="selectpicker" id="taici">
	        		<option value="0">请选择</option>
					<option value="1">会员</option>
					<option value="2">黄金</option>
					<option value="3">白金</option>
					<option value="4">经纪人</option>
	        	</select>
		    </div>
		</div>
		 
		<div class="form-group">
		    <label class="col-sm-3 control-label">地址：</label>
		    <div class="col-sm-6">
			    <select name="province" class="pcc" required></select>
				<select name="city" class="pcc" required></select>
				<select name="area" class="pcc" required></select>
		    </div>
		</div>
		<div class="form-group">
		    <label class="col-sm-3 control-label"></label>
		    <div class="col-sm-6">
	        	<input type="text" name="address" value="" class="form-control" placeholder="请输入会员详细地址"  maxlength="20" autocomplete="off">
		    </div>
		</div>
		<!-- 分公司 -->
		<c:if test="${RoleId == 3 || RoleId == 4}">
		<div class="form-group">
			<label class="col-sm-3 control-label">所属分公司：</label>
			<div class="col-sm-6">
				<select name="store" id="store" class="form-control" disabled="disabled" >
					<option value="${store.storeid }" >${store.title }</option>	
				</select>
			</div>
		</div>
		</c:if>
		<c:if test="${RoleId != 3 && RoleId != 4}">
			<div class="form-group">
			    <label class="col-sm-3 control-label">所属分公司：</label>
			    <div class="col-sm-6">
		        	<select name="store" id="store" class="form-control"  >
		        		<c:if test="${fn:length(storeList) > 0}">
		        			<option value="">请选择分公司</option>
		        			<c:forEach var="ad" items="${storeList}" varStatus="s">
								<option value="${ad.storeid }" >${ad.title }</option>	
							</c:forEach>
		        		</c:if>
		        	</select>
			    </div>
			</div>
		</c:if>
		<!-- 营业部 -->
		<c:if test="${RoleId==3 }">
			<div class="form-group">
			 <label class="col-sm-3 control-label">所属营业部：</label>
			 	<div class="col-sm-6">
			 		<select name="store" id="store" class="form-control"  >
			 			<c:if test="${fn:length(chooseDao) > 0}">
			 				<option value="">请选择营业部</option>
			 					<c:forEach var="dao" items="${chooseDao}" varStatus="s">
								<option value="${dao.id }" >${dao.trueName }</option>	
						</c:forEach>
			 			</c:if>
			 		</select>
			 	</div>
			</div>
		</c:if>
		<c:if test="${RoleId==4 }">
			<div class="form-group">
			 <label class="col-sm-3 control-label">所属营业部：</label>
			 	<div class="col-sm-6">
			 		<select name="store" id="store" class="form-control" disabled="disabled" >
						<option value="${adminSeller.id }" >${adminSeller.trueName }</option>	
			 		</select>
			 	</div>
			</div>
		</c:if>
		<c:if test="${RoleId !=3 && RoleId != 4}">
			<div class="form-group">
			    <label class="col-sm-3 control-label">添加营业部：</label>
			    <div class="col-sm-6">
				    <select name="toBossOneId" id="toBossOneId" class="form-control"  >
			        	<option value="">请选择营业部</option>
			        </select>
			    </div>
			</div>
		</c:if>
	</form>		

</c:if>		 
	</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<script src="${BASE_PATH}/static/js/PCASClass.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	
	//初始化表单验证
	$("#addForm").validate({
		rules:{			
			aphone: {isMobile:true},
		},
		messages:{				
			aphone:{required: "手机号"}, 
			aname:{required: "输入姓名"}, 
			birthday:{required: "请选择会员生日"}, 
			province:{required: "请选择省份"},
			city:{required: "请选择城市"},
			area:{required: "请选择区县"},
		},
		submitHandler:function(form){
			$(form).ajaxSubmit({
				success:function(data){
					switch(data.flag){
					    case 1:
							Kit.alert("会员保存失败，请重新输入");return;
						case 0:
                             window.location.href="${BASE_PATH}/bus/user/index";					
							return;
					}
				}
			});
		}
	});
});
$(".yh").hide();
$("#state").change(function(){
	var state=$("#state").val();
	if(state==1){
		$(".yh").hide();
	}else if(state==2){
		$(".yh").show();
		$(".bb").hide();
		$(".yc").show();
	}else if(state==3){
		$(".yh").show();
		$(".bb").show();
		$(".yc").hide();
	}
})

function query(){
	
	$("#addForm").submit();
		
}
function reset(){
	$("#state").val("1");$("#state").change();
	$("#taici").val("1");$("#taici").change();
	$("#mess").html("");
	$("#addForm")[0].reset();
	new PCAS("province","city","area","河南省","","");
}
function upperCase(){
	var V_MOBILE=/^(1)[0-9]{10}$/;
	var aphone=$("#aphone").val();
	if(V_MOBILE.test(aphone)){
		
		$.post("${BASE_PATH}/bus/user/validate",{aphone:aphone},function(result){
			if(result.flag==0){
				$("#mess").removeClass("red").addClass("green");
				$("#mess").html("该手机号可以使用");return;
			}else{
				$("#mess").removeClass("green").addClass("red");
				$("#mess").html("该手机号已被注册");
				$("#aphone").focus();
				return;
			}
			
		});
	}
}

new PCAS("province","city","area","河南省");

$("#store").change(function(){
	store=$("#store").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseDao",
           data: {"store" : store},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#toBossOneId").empty(); 
               $("#toBossOneId").append("<option value=''>请选择营业部</option>");
               for(var i=0; i<data.object.length;i++){
              	 $("#toBossOneId").append("<option value='"+data.object[i].id+"'>"+data.object[i].trueName+"</option>");
               }
              // $("#toBossOneId").selectpicker("refresh");
           }
       });
    });
</script> 
</body>	  		
</html>